<template>
  <div>
    <div>
      <div class="top-panel">
        <div class="top-item">
          <el-input
            placeholder="输入科室名"
            v-model="keyWord"
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="searchByKeyWord()"
            >查找科室</el-button
          >
        </div>
        <div class="top-item">
          <el-button type="text" @click="back()">返回</el-button>
        </div>
      </div>

      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="doc_name" label="医生姓名"> </el-table-column>
        <el-table-column prop="sex" label="性别"> </el-table-column>
        <el-table-column prop="dept_name" label="所属科室"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="forSentHelp(scope.row.doc_id_card)"
              >申请就医</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :page-size="10"
      layout="prev, pager, next"
      :total="total"
      current-change=""
    >
    </el-pagination>
  </div>
</template>
<script>
import { department } from "@/api";
export default {
  name: "Department",
  data() {
    return {
      keyWord: null,
      tableData: null,
      types: null,
      total: 0,
      data: {
        cur: 1,
        institute_id: 1,
        dept_name: null,
      },
    };
  },
  created() {
    console.log("-------------------");
    console.log(this.$route.query.id);
    this.data.institute_id = this.$route.query.id;
    // this.getDataList();
    this.initData(this.data);
  },
  methods: {
    initData(data) {
      console.log(data);
      department.getDepartmentList(data).then((res) => {
        console.log(res);
        this.tableData = res.data.data.records;
      });
    },
    //分页点击事件
    changePage(val) {
      this.data.cur = val;
      this.getInstituteUserList(data)
    },
    forSentHelp(id) {
      console.log(id);
     
      department.sentHelp(id).then((res) => {
        console.log(res.data);
        if (res.data.code === 200) {
          this.$message({
            message: res.data.msg,
            type: "success",
          });
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },

    searchByKeyWord() {
      this.data.dept_name = this.keyWord;
      this.initData(this.data);
      
    },
    back() {
      this.$router.go(-1);
    },
  },
};
</script>

